<?php

class IngestResourcesTask extends sfBaseTask {
    protected function configure() {
        // // add your own arguments here
        // $this->addArguments(array(
        //   new sfCommandArgument('my_arg', sfCommandArgument::REQUIRED, 'My argument'),
        // ));

        $this->addOptions(array(
                new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name','frontend'),
                new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
                new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'),
                // add your own options here
        ));

        $this->namespace        = 'travide';
        $this->name             = 'ingest-resources';
        $this->briefDescription = 'Reads contents of Resource Upload Directory and Ingests Files into the database';
        $this->detailedDescription = <<<EOF
The [IngestResources|INFO] task does things.
Call it with:

  [php symfony IngestResources|INFO]
EOF;
    }

    protected function execute($arguments = array(), $options = array()) {
        $databaseManager = new sfDatabaseManager($this->configuration);
        $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
        $this->logSection('Ingest', 'Starting Resource Ingestion');
        Doctrine::getTable('CollectionResource')->ingestResourcesFromFileSystem();
        $this->logSection('Ingest', 'Completed Resource Ingestion');
    }
}
